package com.jjw.route.controller;

import java.util.Arrays;
import java.util.Map;

import com.jjw.route.to.BarrageTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.jjw.route.entity.BarrageEntity;
import com.jjw.route.service.BarrageService;
import com.jjw.route.utils.PageUtils;
import com.jjw.route.utils.R;



/**
 * 
 *
 * @author jjw
 * @email 2371671097@qq.com
 * @date 2023-05-12 07:45:21
 */
@RestController
@RequestMapping("route/barrage")
@CrossOrigin
public class BarrageController {
    @Autowired
    private BarrageService barrageService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("route:barrage:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = barrageService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("route:barrage:info")
    public R info(@PathVariable("id") Integer id){
		BarrageEntity barrage = barrageService.getById(id);
        return R.ok().put("barrage", barrage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("route:barrage:save")
    public R save(@RequestBody BarrageEntity barrage){
		barrageService.save(barrage);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("route:barrage:update")
    public R update(@RequestBody BarrageEntity barrage){
		barrageService.updateById(barrage);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("route:barrage:delete")
    public R delete(@RequestBody Integer[] ids){
		barrageService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    @RequestMapping("/insert")
    //@RequiresPermissions("route:barrage:save")
    public R insert(@RequestBody BarrageTo barrage){
        return barrageService.insert(barrage);
    }

    @GetMapping("/data")
    //@RequiresPermissions("route:barrage:save")
    public R getData(){
        return barrageService.getData();
    }

    @GetMapping("/list")
    //@RequiresPermissions("route:barrage:save")
    public R getList(){
        return barrageService.getList();
    }
    @GetMapping("/addData")
    //@RequiresPermissions("route:barrage:save")
    public R addData(@RequestParam("content") String content){
        return barrageService.addData(content);
    }
}
